import RenderContext from "@/views/cg/lib/RenderContext.ts";

// IndexBuffer 没有name
export default class GLIndexBuffer {
  constructor( data, dimension = 3, mode) {

    this.dimension = dimension
    this.gl = RenderContext.getGL()
    this.program = RenderContext.getProgram()

    // 初始化buffer
    this.buffer = this.gl.createBuffer()
    this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, this.buffer)
    this.gl.bufferData(
      this.gl.ELEMENT_ARRAY_BUFFER,
      data,
      mode || this.gl.STATIC_DRAW
    )

    // indexBuffer 不需要 enable
    // this.gl.enableVertexAttribArray(this.location)
  }
  // 关联
  associate(){
    this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, this.buffer)
    /*
    const type = this.gl.FLOAT
    const normalized = false
    const stride = 0
    const offset = 0
    this.gl.vertexAttribPointer(
      this.location,
      this.dimension,
      type,
      normalized,
      stride,
      offset
    )
    */
  }
}
